<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>JsSpec test</title>
	<link rel="stylesheet" href="js-spec.css" type="text/css" charset="utf-8" />
	<script type="text/javascript" src="../lib/prototype.js"></script>
	<script type="text/javascript" src="../dist/jsspec.js"></script>
</head>

<body>
  
  <div id="some_container">
    <span class="something"></span>
  </div>
  
<script type="text/javascript" charset="utf-8">  
  with (Spec) {
    
    describe("js-spec", function() { with(this) {
      
      it("should pass when doing simple comparisons", function() {
        (1).should( equal(1) );
        (1).should( be_less_than(2) );
        (1).should( be_greater_than(0) );
        (1).should_not( equal(2) );
        (1).should( be(1) );
        (1).should_not( be("1") );
      });
      
      it("should pass when checking if a value is within a delta of another", function() {
        // first argument is the target, second one the maximum allowed difference between both numbers
        (1.0).should( be_close(1.05, 0.1) );
        (1.0).should_not( be_close(1.5, 0.1) );
      });
      
      it("should pass when checking if a method changes an object", function() {
        [1, 2, 3, 4].should_not( change("length").in_response_to("size") );
        // the next example would also pass if you changed 'to(3)' to 'from(4)' or 'by(-1)'
        [1, 2, 3, 4].should( change("length").to(3).in_response_to("pop") );
        // it also works for functions, and you can even pass parameters to them:
        [1, 2, 3, 4].should( change("first").to(0).in_response_to("unshift", 0) );
      });

      it("should pass when checking how many elements has an enumerable", function() {
        $("some_container").should( have(1, "childElements") );
        [1, 2, 3, 4].should( have(2, "slice", 0, 2) ); // equivalent to [1, 2, 3, 4].slice(0, 2).length.should( equal(2) )
        $("some_container").down("span").should_not( have_at_least(1, "childElements") );
        
      });
      
      it("should pass when asking if an enumerable includes some elements", function() {
        [1, 2, 3, 4].should( include(1, 2) );
        [1, 2, 3, 4].should_not( include(0) );
      })
      
      it("should match strings to regexps", function() {
        "to be or not to be".should_not( match(/^2b|[^b]{2}$/) );
        "Something".should( match(/^[Ss]/) );
      });

      it("should match DOM nodes to selectors correctly", function() {
        $("some_container").should( match("#some_container") );
        $("some_container").down(".something").should( match("#some_container .something") );
      });
      
      it("should pass when asking if an object responds to a method", function() {
        [1, 2, 3].should( respond_to("size") );
        "string".should_not( respond_to("asdfg") );
      });
      
      it("should pass when asking if an object satisfies a block", function() {
        [1, 2, 3].should( satisfy(function(list) {
          return list.length > 2;
        }));
        
        "string".should_not( satisfy(function(word) {
          return word.startsWith("cuack");
        }));
      });
      
    }});
    
  }
  
  Specs.run();
</script>

</body>
</html>